package com.itheima.d09_reflect_constructor;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Test {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class< Cat> cls= Cat.class;
        Constructor<?>[]constructors=cls.getConstructors();
        for (Constructor<?> constructor : constructors){
            System.out.println(constructor);
        }
        System.out.println("------------------");
        Constructor<?>[]declaredConstructors=cls.getDeclaredConstructors();//获取所有构造方法
        for (Constructor<?> declaredConstructor : declaredConstructors){
            System.out.println(declaredConstructor);
        }
        System.out.println("------------------");
        Constructor<?> constructor=cls.getConstructor(String.class,int.class);
        System.out.println(constructor);
        System.out.println("=============");
        Cat cat= (Cat) constructor.newInstance("徐文赛",1);
        System.out.println(cat);

        Constructor<Cat> cat1 = cls.getConstructor(String.class, int.class);
        Cat cat2=cat1.newInstance("小猫",1);
        System.out.println(cat2);
        System.out.println("=============");
        Constructor<Cat> declaredConstructor = cls.getDeclaredConstructor(String.class);
        Object cat3=declaredConstructor.newInstance("小猫",3);
    }
}
